var mongoose = require('mongoose');
var Schema = new mongoose.Schema({
    openid: String,
    thirdSession: String,
});

// 添加 mongoose 静态方法 
Schema.statics.valid = function(token) {
    // console.log(token);
    return new Promise( (resolve, reject) => {
        if (!token) {
            reject();
        }
        this.model('Member').findOne({
            token: token,
        })
        .select('-session_key')
        .exec(function(err, user) {
            // console.log(user);
            if (user) {
                resolve(user);
            } else {
                reject();
            }
        });
    });
}

module.exports = mongoose.model('Member', Schema)